﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="BindableValue.cs" company="">
//   
// </copyright>
// <summary>
//   The bindable value.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Libium
{
    using System;

    /// <summary>
    /// The bindable value.
    /// </summary>
    /// <typeparam name="T">
    /// </typeparam>
    public class BindableValue<T> : IBindableValue<T>
    {
        #region Fields

        /// <summary>
        ///   The _value.
        /// </summary>
        private T _value;

        #endregion

        #region Public Events

        /// <summary>
        ///   The value changed.
        /// </summary>
        public event Action<IBindableValue<T>> ValueChanged;

        #endregion

        #region Public Properties

        /// <summary>
        ///   Gets or sets the value.
        /// </summary>
        public T Value
        {
            get
            {
                return this._value;
            }

            set
            {
                if (this._value.Equals(value))
                {
                    return;
                }

                this._value = value;
                this.OnValueChanged();
            }
        }

        #endregion

        #region Public Methods and Operators

        /// <summary>
        ///   The on value changed.
        /// </summary>
        public virtual void OnValueChanged()
        {
            if (this.ValueChanged != null)
            {
                this.ValueChanged(this);
            }
        }

        #endregion
    }
}